/*
 * @Author: morrenhao 2311090504@qq.com
 * @Date: 2022-05-17 15:04:03
 * @LastEditors: morrenhao 2311090504@qq.com
 * @LastEditTime: 2022-07-21 14:27:45
 * @FilePath: \weex_study\src\utils\config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//全局配置
var navigator = weex.requireModule('navigator');
var modal = weex.requireModule('modal');
const DEBUG_HEADLER = "http://t.cn?test=";
const DEFAULT_DEBUG_IP = "http://192.168.255.10:9090";
const DEFAULT_RELEASE_IP = "file://";
const DIST = "/dist";
const COMPONENTS = "/components/";
// const IMAGE_URL = IS_DEBUG == true ? "file:///android_asset/dist/image/" : "http://192.168.255.10:8081./image/"
const IMAGE_URL = "file:///android_asset/dist/image/"
var IS_DEBUG = true;

function getUrl() {
    if (IS_DEBUG) {
        return DEBUG_HEADLER + DEFAULT_DEBUG_IP + COMPONENTS;
    } else {
        return DEFAULT_RELEASE_IP + DIST + COMPONENTS;
    }
}
//==================Start Navigator ==================================================//
export function push(url, callback) {
    navigator.push({
        url: getUrl() + url,
        animated: "true"
    }, event => {
        callback("jump success")
    });
}

export function pop() {
    navigator.pop({
        animated: "true"
    })
}

//==================End Navigator ==================================================//

//==================Start Toast ==================================================//
export function toast(msg, showTime = 0.5) {
    modal.toast({
        message: msg,
        duration: 0.3
    })
}

export function alert(msg = 'no Message', confirm = '确认') {
    modal.alert({
        message: msg,
        okTitle: confirm
    })
}

export function weexAlert(weexInfo, confirm = '确认') {
    modal.alert({
        message: deComposeWeexEnvironment(weexInfo),
        okTitle: confirm
    })
}

//==================End Toast ==================================================//

export function getBaseImageUrl() { return IMAGE_URL }

export function deComposeWeexEnvironment(weexInfo) {
    if (null == weexInfo || undefined == weexInfo) {
        return 'Wexx Info no data';
    }

    return 'appName = '
        .concat(weexInfo.appName)
        .concat('\n')
        .concat('appVersion = ')
        .concat(weexInfo.appVersion)
        .concat('\n')
        .concat('platform = ')
        .concat(weexInfo.platform)
        .concat('\n')
        .concat('weexVersion = ')
        .concat(weexInfo.weexVersion)
        .concat('\n')
        .concat('osVersion = ')
        .concat(weexInfo.osVersion)
}